package com.locatme.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.main.locatme.R;

import java.util.List;

public class


        EventsViewAdapter extends ArrayAdapter<String> {
    private final Activity activity;
    private final List<String> values;

    public EventsViewAdapter(Activity activity, List<String> values) {
        super(activity, R.layout.rowlayout, values);
        this.activity = activity;
        this.values = values;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView iconStatut = (ImageView) rowView.findViewById(R.id.iconStatut);
        String[] tab;
        if (!values.get(position).contains(";")) {
            textView.setText(values.get(position));
            iconStatut.setVisibility(View.INVISIBLE);
        } else {
            // changement icone selon le statut de l'invitation
            tab = values.get(position).split(";");
            textView.setText(tab[0]);
            if (tab[1].equalsIgnoreCase("1")) {
                iconStatut.setImageResource(R.drawable.ic_statut_yes);
            } else if (tab[1].equalsIgnoreCase("2")) {
                iconStatut.setImageResource(R.drawable.ic_statut_maybe);
            } else if (tab[1].equalsIgnoreCase("3")) {
                iconStatut.setImageResource(R.drawable.ic_statut_no);
            } else {
                iconStatut.setImageResource(R.drawable.ic_statut_default);
            }
        }
        return rowView;
    }
}
